package day11.ThreadTest;

public class Test2 {
    public static void main(String[] args) {
        //封装代码的对象
        R1 r1 = new R1();
        Thread t1 = new Thread(r1);
        Thread t2 = new Thread(r1);

        t1.start();
        t2.start();
        //获得main线程
        Thread tmain = Thread.currentThread();
        System.out.println(tmain.getName());

    }
    /*
    用来封装代码
    run()代码要放入线程执行
     */
    static class R1 implements Runnable {
        @Override
        public void run() {
            //获得正在执行的线程对象
            Thread t = Thread.currentThread();
            String n = t.getName();
            for (int i = 1; i <= 100; i++) {
                System.out.println(
                        n + " - " + i
                );
            }
        }
    }
}
